package main

import (
	"net/http"
	"runtime"
)

func Server2() {
	Runtime()

	//goroutine
	http.HandleFunc("/goroutine", func(writer http.ResponseWriter, request *http.Request) {
		WriteGoRoutine("/Users/fanshuai/goroutine.pprof")
		writer.Write([]byte("OK"))
		writer.WriteHeader(200)
	})

	//profile
	http.HandleFunc("/profile", func(writer http.ResponseWriter, request *http.Request) {
		WriteCPU("/Users/fanshuai/cpu.pprof", 30)
		writer.Write([]byte("OK"))
		writer.WriteHeader(200)
	})

	//heap
	http.HandleFunc("/heap", func(writer http.ResponseWriter, request *http.Request) {
		WriteMem("/Users/fanshuai/mem.pprof")
		writer.Write([]byte("OK"))
		writer.WriteHeader(200)
	})

	//block
	http.HandleFunc("/block", func(writer http.ResponseWriter, request *http.Request) {
		WriteBlock("/Users/fanshuai/block.pprof")
		writer.Write([]byte("OK"))
		writer.WriteHeader(200)
	})

	//mutex
	http.HandleFunc("/mutex", func(writer http.ResponseWriter, request *http.Request) {
		WriteMutex("/Users/fanshuai/mutex.pprof")
		writer.Write([]byte("OK"))
		writer.WriteHeader(200)
	})

	//threadcreate
	http.HandleFunc("/threadcreate", func(writer http.ResponseWriter, request *http.Request) {
		WriteThreadCreate("/Users/fanshuai/threadcreate.pprof")
		writer.Write([]byte("OK"))
		writer.WriteHeader(200)
	})

	http.HandleFunc("/trace", func(writer http.ResponseWriter, request *http.Request) {
		WriteTrace("/Users/fanshuai/trace.log", 1)
		writer.Write([]byte("OK"))
		writer.WriteHeader(200)
	})

	runtime.SetBlockProfileRate(1000 * 1000)
	runtime.SetMutexProfileFraction(1)

	http.ListenAndServe(":9000", nil)
}
